/**
 * 记录发生错误时，最后一个交互事件
 */
let lastEvent: Event | null;
let lastEventPath: any[];

['click', 'keydown'].forEach((eventType: string) => {
    document.addEventListener(eventType, event => {
        lastEvent = event;
        // @ts-ignore
        lastEventPath = event.path || event.composedPath();
    }, {
        capture: true, // 事件在捕获阶段触发
        passive: true // 不调用preventDefault()阻止默认行为
    })
});

/**
 * 获取最后一次的事件调用栈
 */
export const getLastEventPath = () => {
    return lastEventPath;
}

/**
 * 获取最近一次的事件
 */
export const getLastEvent = () => {
    return lastEvent;
}
